package com.springboot.cropsboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.cropsboot.entity.Dikuai;
import com.springboot.cropsboot.entity.Pici;
import com.springboot.cropsboot.mapper.DikuaiMapper;
import com.springboot.cropsboot.qpage.QPage;
import com.springboot.cropsboot.service.IDikuaiService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.cropsboot.util.ResultView;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2023-12-02
 */
@Service
public class DikuaiServiceImpl extends ServiceImpl<DikuaiMapper, Dikuai> implements IDikuaiService {

    @Override
    public ResultView getPageList(QPage qPage, Dikuai obj) {
        QueryWrapper<Dikuai> queryWrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(obj.getDikuaiName())){
            queryWrapper.like("dikuai_name",obj.getDikuaiName());
        }
        IPage iPage = new Page(qPage.getOffset(), qPage.getLimit());
        IPage<Dikuai> mapList = this.page(iPage,queryWrapper);
        return ResultView.ok(mapList);
    }

    @Override
    public ResultView saveObj(Dikuai obj) {
        boolean count=this.save(obj);
        if(!count){
            return ResultView.error("数据异常，操作失败");
        }
        return ResultView.ok();
    }

    @Override
    public ResultView updateObj(Dikuai obj) {
        boolean count=this.updateById(obj);
        if(!count){
            return ResultView.error("数据异常，操作失败");
        }
        return ResultView.ok();
    }

    @Override
    public ResultView deleteObj(Dikuai obj) {
        boolean count=this.removeById(obj.getId());
        if(!count){
            return ResultView.error("数据异常，操作失败");
        }
        return ResultView.ok();
    }

}
